package leetcode;

/**
 * @program: datastructureandalogorithm
 * @description:
 * @author: hmx
 * @create: 2021-12-05 10:51
 **/
public class LeetCode5943 {

    //快慢指针
    public ListNode deleteMiddle(ListNode head) {

        ListNode tou = new ListNode(0, head);
        ListNode first = head;
        ListNode second = tou;
        while (first != null && first.next != null) {
            first = first.next.next;
            second = second.next;
        }
        //删除节点
        second.next = second.next.next;
        return tou.next;
    }

    //两次遍历
    /*public ListNode deleteMiddle(ListNode head) {

        ListNode tou = new ListNode(0, head);
        ListNode temp = head;
        int count = 0;
        //得到节点个数
        while (temp != null) {
            count++;
            temp = temp.next;
        }
        int avg = count / 2;
        temp = tou;
        for (int i = 0; i < avg; i++) {
            temp = temp.next;
        }
        //删除节点
        temp.next = temp.next.next;
        return tou.next;
    }*/

}
